package com.lantian.teacher.exception;

import com.lantian.common.result.Result;
import com.lantian.common.utils.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @name:
 * @description: 异常处理
 * @author: meet
 * @create: 2020-04-28 00:15
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();

        return Result.error().message("出错了");
    }

    @ExceptionHandler(EduException.class)
    @ResponseBody
    public Result error(EduException e){
        e.printStackTrace();
        log.error(e.getMessage());
//        log.error(ExceptionUtil.getMessage(e));
//        return Result.error().code(e.getCode()).message(e.getMessage());
        return Result.error().code(e.getCode()).message(e.getMsg());
    }
}